package com.zbkj.crmeb.store.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.common.CommonPage;
import com.crmeb.core.common.CommonResult;
import com.common.PageParamRequest;
import com.github.pagehelper.PageHelper;
import com.zbkj.crmeb.store.model.SupplierUnmatchBrand;
import com.zbkj.crmeb.store.service.SupplierUnmatchBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 供应商未匹配品牌表 前端控制器
 * </p>
 *
 * @author wuzp
 * @since 2022-04-24
 */
@RestController
@RequestMapping("/api/admin/store/match/brand")
@Api(tags = "总后台-供应商未匹配品牌")
public class SupplierUnmatchBrandController {

    @Autowired
    private SupplierUnmatchBrandService supplierUnmatchBrandService;

    @ApiOperation(value = "未匹配品牌列表")
    @GetMapping(value = "/list")
    public CommonResult<Object> getList(Integer type,PageParamRequest pageParamRequest){
        PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
        List<SupplierUnmatchBrand> unMatchBrandList = supplierUnmatchBrandService.list(Wrappers.<SupplierUnmatchBrand>lambdaQuery()
                .eq(SupplierUnmatchBrand::getIsDel, 0)
                .eq(type != null, SupplierUnmatchBrand::getType, type)
        );
        return CommonResult.success(CommonPage.restPage(unMatchBrandList));
    }

    @ApiOperation(value = "批量删除未匹配品牌")
    @DeleteMapping(value = "/delete")
    public CommonResult<Object> delete(@NotEmpty(message = "id不能为空") @RequestBody Set<Integer> ids){
        return supplierUnmatchBrandService.update(Wrappers.<SupplierUnmatchBrand>lambdaUpdate()
                .set(SupplierUnmatchBrand::getIsDel, 1).in(SupplierUnmatchBrand::getId, ids)) ? CommonResult.success() : CommonResult.failed();
    }

}

